# @Time: 2023/1/29 13:10
# @Author: 张江南
# @File: 
# @Project: 代码
import xlwings as xw

app = xw.App(visible=False, add_book=False)
app.display_alerts = True  # 显示警报()
app.screen_updating = False  # 屏幕更新(应用中)

# 文件位置：filepath，打开test文档，然后保存，关闭，结束程序
filepath = '../excel/csdn001.xlsx'
wb = app.books.open(filepath)
sh1 = wb.sheets['sheet1']

info = wb.sheets['sheet1'].used_range
total = info.last_cell.row
# total = wb.sheets['sheet1'].use_range.last_cell.row
# total = 200
start = 2765
end = start + 100
num = start
try:
    while num < total:
        s = 'A{}:L{}'.format(start, end)
        data = sh1.range(s).value
        num += len(data)
        start = end + 1
        end = end + 100
        if end > total:
            end = total
        for i, item in enumerate(data):
            flag = True
            for index, tt in enumerate(item):
                if tt is None or tt == "":
                    flag = False
                    break
            if flag:
                item[5] = 1
                item[8] = int(item[8])
                item[9] = int(item[9])

except Exception as e:
    print("数据库操作异常：\n", e)
finally:
    wb.close()
    app.quit()
    app.kill()
